#pragma once

#include <AVUIContentControl.h>

namespace AVUI {

class StyleSelector;

class HeaderedContentControl : public ContentControl
{
    friend class ItemsControl;
public:
    HeaderedContentControl() : m_headerIsNotLogical(false), m_headerIsItem(false) { };
    ~HeaderedContentControl() { };

    DECLARE_ELEMENT(HeaderedContentControl, ContentControl);

    DECLARE_DEPENDENCY_PROPERTY(Header);
    TRefCountedPtr<Object> get_Header() { return GetValue(get_HeaderProperty()); }
    void set_Header(Object* pValue) { return SetValue(get_HeaderProperty(), pValue); }

    DECLARE_READONLY_DEPENDENCY_PROPERTY(HasHeader)
    bool get_HasHeader() { return AVUI::UnboxValue<bool>(GetValue(get_HasHeaderProperty())); }

    DECLARE_DEPENDENCY_PROPERTY(HeaderTemplate);
    TRefCountedPtr<DataTemplate> get_HeaderTemplate() { return (DataTemplate*)(Object*)GetValue(get_HeaderTemplateProperty()); }
    void set_HeaderTemplate(DataTemplate* pValue) { SetValue(get_HeaderTemplateProperty(), (Object*)pValue); } 

    DECLARE_DEPENDENCY_PROPERTY(HeaderTemplateSelector);
    TRefCountedPtr<DataTemplateSelector> get_HeaderTemplateSelector() { return (DataTemplateSelector*)(Object*)GetValue(get_HeaderTemplateSelectorProperty()); }
    void set_HeaderTemplateSelector(DataTemplateSelector* pValue) { SetValue(get_HeaderTemplateSelectorProperty(), (Object*)pValue); } 

protected:

    virtual void OnHeaderChanged(Object* pOldHeader, Object* pNewHeader);

    virtual TRefCountedPtr<Object> get_LogicalChildren();

private:
    static void StaticConstructor();

    bool get_HeaderIsItem() const { return m_headerIsItem; }
    void set_HeaderIsItem(bool headerIsItem) { m_headerIsItem = headerIsItem; }

    bool get_HeaderIsNotLogical() const { return m_headerIsNotLogical; }
    void set_HeaderIsNotLogical(bool headerIsNotLogical) { m_headerIsNotLogical = headerIsNotLogical; }

    void PrepareHeaderedContentControl(Object* pItem, DataTemplate* pItemTemplate, DataTemplateSelector* pItemTemplateSelector);

    static void OnHeaderChanged(DependencyObject* pDO, DependencyPropertyChangedEventArgs* e);

    bool m_headerIsNotLogical;
    bool m_headerIsItem;

};

}; // namespace AVUI
